package com.shu.driftbook.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;

import com.opensymphony.xwork2.ActionSupport;
import com.shu.driftbook.dao.Book;
import com.shu.driftbook.service.BookService;
import com.shu.driftbook.service.DriftQueueService;
import com.shu.driftbook.service.DriftQueueService.Reader;

public class IndexAction extends ActionSupport implements ServletRequestAware{
	private BookService service;
	private DriftQueueService driftservice;
	private List<Book> result;
	private List<Reader> reader;
	private HttpServletRequest request;
	private HttpSession session;
	
	public BookService getService() {
		return service;
	}

	public void setService(BookService service) {
		this.service = service;
	}

	public List<Book> getResult() {
		return result;
	}

	public void setResult(List<Book> result) {
		this.result = result;
	}
	
	public String execute(){
		result=service.findInIndex();
		reader=driftservice.findReader(result);
		if(session.isNew()||session.getAttribute("username")==null
				||session.getAttribute("username").toString()=="")
			return ERROR;
		else
			return SUCCESS;
	}

	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		this.request=arg0;
		this.session=request.getSession();
	}

	public DriftQueueService getDriftservice() {
		return driftservice;
	}

	public void setDriftservice(DriftQueueService driftservice) {
		this.driftservice = driftservice;
	}

	public List getReader() {
		return reader;
	}

	public void setReader(List reader) {
		this.reader = reader;
	}
}
